package com.rankeiot.compiler;

import net.logicsquad.minifier.MinificationException;
import net.logicsquad.minifier.Minifier;
import net.logicsquad.minifier.css.CSSMinifier;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;

/**
 * css 代码压缩
 */
public class CssCompiler implements ICompiler{
    @Override
    public String compile(String source) {
        Reader input = new StringReader(source);
        StringWriter out = new StringWriter();
        Minifier minifier = new CSSMinifier(input);
        try {
            minifier.minify(out);
            return out.toString();
        } catch (MinificationException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void close() throws IOException {

    }
}
